package pkg

import (
	v1 "wonlicsys/api/v1"
	"wonlicsys/database"
	"wonlicsys/pkg/daemonPack"
	"wonlicsys/pkg/dingding"
	"wonlicsys/pkg/tryErr"
	"wonlicsys/router"
)

var AppSer *App

type App struct {
	DingPkg *dingding.AliDing
}

func GetInstance() *App {
	return AppSer
}

//开始项目  顺序不能错
func Start() error {
	AppSer = new(App)
	if err := AppSer.Startup(
		v1.InitConf,                //初始化配置文件
		database.InitRedis,         //初始化redis
		dingding.NewAllDingService, //初始化钉钉
		daemonPack.DaemonStart,     //deam模式开启
		router.StartHttp,           //初始化http
	); err != nil {
		return err
	}

	return nil
}

//Startup ..
func (app *App) Startup(fns ...func() error) error {
	return tryErr.SerialUntilError(fns...)()
}
